var MY_HOME_PAGE = (function() {

	/**
	 * 加载大屏数据（除地图数据外）
	 */
	function loadItem(){

		var datePatten = $('.date_fillter').eq(0).val();

		var params = { datePatten:datePatten ,'ua':ua};

		$.ajax({
			type: "POST",
			url: "invs_home_page.do/load",
//	        dataType: "json",
//	        contentType:"application/json",
//	        data: JSON.stringify(params),
			data: params,
			async: true,//异步调用
			success: function(data) {

				WeKnow.closeLoading();
				if (!WeKnow.filterAjaxResult(data)) return false; // session过期check

				if (data.errcode == 0) {
					// 监控的总机构数
					$('#allInstitutionCnt').html(data.homePageData.institutionStatistics.allInstitutionCnt);
					// 监控的公立医疗机构数
					$('#institutionCntBy01').html(data.homePageData.institutionStatistics.institutionCntBy01);
					//监控的民营医院数
					$('#institutionCntBy02').html(data.homePageData.institutionStatistics.institutionCntBy02);
					//监控的门诊部数
					$('#institutionCntBy03').html(data.homePageData.institutionStatistics.institutionCntBy03);
					//监控的诊所（医务室）数
					$('#institutionCntBy04').html(data.homePageData.institutionStatistics.institutionCntBy07);
					//监控的乡镇院数
					$('#institutionCntBy05').html(data.homePageData.institutionStatistics.institutionCntBy05);
					//监控的村卫生室数
					$('#institutionCntBy06').html(data.homePageData.institutionStatistics.institutionCntBy06);
					//监控的社区卫生服务中心数
					$('#institutionCntBy07').html(data.homePageData.institutionStatistics.institutionCntBy04);
					//绘制电子台账异常医疗机构饼图
					drawActionDailyPie(data.homePageData.actionDailyPie);
					//绘制处方异常医疗机构分布饼图
					drawpresDailyPie(data.homePageData.presDailyPie);
					//已经处置异常数
					$('#dateErrorHandleCnt').html(data.homePageData.dateErrorHandleCnt.part);
					//已处置占比
					$('#dateErrorHandleRate').html(data.homePageData.dateErrorHandleCnt.all == 0 ?0+"%":(data.homePageData.dateErrorHandleCnt.part*100/data.homePageData.dateErrorHandleCnt.all).toFixed(2)+"%");
					//异常台账数
					$('#dateActionCnt').html(data.homePageData.dateActionCnt.part);
					//异常台账数占比
					$('#dateActionRate').html(data.homePageData.dateActionCnt.all == 0 ?0+"%":(data.homePageData.dateActionCnt.part*100/data.homePageData.dateActionCnt.all).toFixed(2)+"%");
					//违规处方数
					$('#datePresCnt').html(data.homePageData.datePresCnt.part);
					//违规处方数占比
					$('#datePresRate').html(data.homePageData.datePresCnt.all == 0 ?0+"%":(data.homePageData.datePresCnt.part*100/data.homePageData.datePresCnt.all).toFixed(2)+"%");
					// 显示实时监控记录
					showRealTimeMonitor2(data.realTimeMonitorList);
				} else if (data.errcode == -1 ) {
					WeKnow.errorMsg( data.errMsg );
				} else {
					WeKnow.systemMsg('查询失败，请重新登录');
				}
			}
		});
	}

	/**
	 * 加载大屏地图数据
	 */
	function loadMap(){

		//var datePatten = $('.date_fillter').eq(0).val();
		//默认查询近一周数据
		var datePatten = 1;

		var params = { datePatten:datePatten ,'ua':ua};

		$.ajax({
			type: "POST",
			url: "invs_home_page.do/load_map",
//	        dataType: "json",
//	        contentType:"application/json",
//	        data: JSON.stringify(params),
			data: params,
			async: true,//异步调用
			success: function(data) {

				WeKnow.closeLoading();
				if (!WeKnow.filterAjaxResult(data)) return false; // session过期check

				if (data.errcode == 0) {
					//累计监管处方数
					$('#allPresCnt').text(data.homePageData.allPresCnt);
					//累计监管台账数
					$('#allActionCnt').text(data.homePageData.allActionCnt);
					// 绘制不良执业行为散点图
					drawMap(data.badPracticingTown,data.badBehaviorTown);
					//绘制处方违规树状图
					drawBadPracticingBehavior(data.homePageData.presDailyByType);
					//处方违规数趋势（折线图）
					drawPreTimeLine(data.homePageData.violateTimeLine);
					//绘制台账异常数趋势图
					drawWarningTimeLine(data.homePageData.warningTimeLine);
				} else if (data.errcode == -1 ) {
					WeKnow.errorMsg( data.errMsg );
				} else {
					WeKnow.systemMsg('查询地图、树状图、折线图数据失败，请重新登录');
				}
			}
		});
	}

	//设置时间
	function setDateTime(){
		var t = null;
		t = setTimeout(time, 1000); //開始运行
		function time() {
			clearTimeout(t); //清除定时器
			dt = new Date();
			var weekDay = new Array("日", "一", "二", "三", "四", "五", "六");
			var y = dt.getFullYear();
			var mt = dt.getMonth() + 1<10?'0'+(dt.getMonth()+ 1):dt.getMonth()+ 1;
			var day = dt.getDate()<10?'0'+dt.getDate():dt.getDate();
			var h = dt.getHours()<10?'0'+dt.getHours():dt.getHours(); //获取时
			var m = dt.getMinutes()<10?'0'+dt.getMinutes():dt.getMinutes(); //获取分
			var s = dt.getSeconds()<10?'0'+dt.getSeconds():dt.getSeconds(); //获取秒
			var week = dt.getDay();
			document.querySelector(".showTime").innerHTML =
				"<h1 class='weekDay' style='float:right;font-size:0.25rem;'>星期"+weekDay[week]+"</h1>" +
				"<h1><span style='font-size:0.45rem;'>"+h+":"+m+":"+s+"</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style='font-size:0.25rem;'>"+y+"/"+mt+"/"+day+"</span></h1>"
			t = setTimeout(time, 1000); //设定定时器，循环运行
		}
	}

	// 绘制地图
	function drawMap(badPracticingTown,badBehaviorTown){

		var uploadedDataURL = WeKnow.getRealPath()+ "/js/mapData/geoJson/linan.json?V0.2";

		var isTest = $('#isTest').val();// 是否演示的卫监机构
		if (isTest == 1) {
			uploadedDataURL = WeKnow.getRealPath()+ "/js/mapData/geoJson/testArea.json?V0.2";
		}

		var name = 'linan';

		$.get(uploadedDataURL, function(geoJson) {

			echarts.registerMap(name, geoJson);//注册 地图

			var myChart = echarts.init(document.getElementById('map_area'));
			window.addEventListener('resize', function () {
				myChart.resize();
			});
			/*
             *
             * 地图散点位置
             *
             * 异常行为 清凉峰镇 [118.9189,30.1590]
             * 不良：岛石镇 [118.9189,30.2590]
             *
             * */
//		    var geoCoordMap = {
//		    	    "清凉峰镇": [118.9189,30.1590],  //
//		    	    "岛石镇": [118.9189,30.2590]
//	    	};

			// 将坐标与值对应并反映在地图上
			var convertData = function () {
				var res = [];
				$(badPracticingTown).each(function(idx,a){
					var one = {};
					one.name = a.town;
					var value = [];
					value.push(a.longitude);
					value.push(a.latitude);
					value.push(a.town);//区域id
					value.push(a.value);//不良行为显示为红色
					one.value = value;
					res.push(one);
				});
				return res;
			};

			myChart.setOption(option = {
				title: {
					// text: "xx省 xx市 地图",
					left: 'center',
					textStyle: {
						color: '#000'
					}
				},
				visualMap: {
					type: 'piecewise',
					textStyle: {
						color: '#A5CCED'
					},
					pieces: [
						{min: 2, max: 2, label: '异常行为', color: 'yellow'},
						{min: 3, max: 3, label: '不良执业', color: 'red'},
						{min: 1, max: 1, label: '正常行为', color: 'green'}
					],
					color: ['#e3bf4c', '#be4f51'],
					borderWidth:"2px",
					orient:"horizontal",
					left:"right", //组件离容器左侧的距离,'left', 'center', 'right','20%'
					top:"top"
				},
				geo: {
					map: 'linan',
					zoom: 1.2,// 改变这个值的大小就可以了
					label: {
						normal: {
							show: true,
							textStyle:{
								color:'#A5CCED',
								fontsize:'2rem'
							}
						},

						emphasis: {
							show: true
						}
					},
					itemStyle: {
						normal: {
							areaColor: '#132759',//地图背景色
							borderColor: '#A5CCED'
						},

						emphasis: {
							areaColor: 'yellow'//鼠标移入时颜色
						}
					}
				},
				series: [{
					name:'不良执业',
					type: 'effectScatter',
					coordinateSystem: 'geo',
//		            data: convertData([
//		                {name: "清凉峰镇", value: 120},
//		                {name: "岛石镇", value: 10}
//		            ]),
					symbolSize: function (val) {
						return 15;
					},
					data: convertData(),
					label: {
						normal: {
							formatter: '{b}',
							position: 'right',
							show: false,
							textStyle:{
								fontSize: 20,
								color:'white'
							}
						},
						emphasis: {
							show:false,
							textStyle: {
								fontSize: 20,
								color: 'yellow'
							}
						}
					},
					itemStyle: {
						normal: {
							borderColor: 'rgba(0,168,255,.6)',
							borderWidth:2,
							areaColor: 'yellow',
						},
						emphasis: {
							borderColor: 'rgba(0,168,255,.6)',
							borderWidth:2,
							areaColor: 'rgba(0,81,138,.3)',
						}
					},
					animation: false
				}]
			});

			var handler = function eConsole(param){
				if(param.componentType === 'series' && param.componentSubType === 'effectScatter'){//散点
					if(param.value && param.value.length > 3) {
						var townId = param.value[2];//地区ID
						var today = $('.date_fillter').eq(0).val();// 0：今日  1：本周
						if(param.value[3] == 2){
							var status = -2;//状态
							WeKnow.submit("main.do?initPageTitle=invs_summarize.do&townId=" + townId + "&today=" + today + "&status=" + status);
						}else if(param.value[3] == 3){
							var status = -1;//状态
							WeKnow.submit("main.do?initPageTitle=invs_prescription_violate.do&townId=" + townId + "&today=" + today + "&status=" + status);
						}
					}
				}
			}

			//先解除全部绑定，否则多次绑定会执行多次方法
			myChart.off('click');

			//点击事件的监听,必须在setOption方法执行后创建
			myChart.on('click', handler);
		});
	}
	//绘制处方违规树状图
	function drawBadPracticingBehavior(data) {
		if (data.length == 0) {
			return;
		} else {
			var nameData = [];
			var valueData = [];
			for(i=0;i<data.length;i++){
				nameData.push(data[data.length-i-1].name);
				valueData.push(data[data.length-i-1].value);
			}
		}
		// 1. 实例化对象
		var myChart = echarts.init(document.querySelector("#badPracticingBehavior"));
		// 2. 指定配置项和数据
		option = {
			color:['#799AEC'],
			xAxis : [
				{
					type : 'value',
					"show":false
				}
			],
			yAxis : [
				{
					type : 'category',
					data : nameData,
					axisLine:{
						lineStyle:{
							color: "#8db6d8",
							fontSize:fontChart(0.17)
						}
					}
				}
			],
			grid: {
				left: '1%',
				right: '1%',
				bottom: '3%',
				top: '2%',
				containLabel: true
			},
			series : [
				{
					type:'bar',
					barMinHeight: 12,
					itemStyle : { normal: {label : {show: true, position: 'insideRight'}}},
					data:valueData
				}
			]
		};
		// 3. 配置项和数据给我们的实例化对象
		myChart.setOption(option);
		// 4. 当我们浏览器缩放的时候，图表也等比例缩放
		window.addEventListener("resize", function() {
			// 让我们的图表调用 resize这个方法
			myChart.resize();
		});
	};
	//绘制电子台账异常医疗机构饼图
	function drawActionDailyPie(data) {
		if (data.length == 0) {
			return;
		} else {
			var nameData = [];
			var valueData = [];
			for(i=0;i<data.length;i++){
				nameData.push(data[i].name);
				valueData.push(data[i]);
			}
		}
		// 1. 实例化对象
		var myChart = echarts.init(document.querySelector("#actionDailyPie"));
		// 2. 指定配置项和数据
		option = {
			tooltip : {
				trigger: 'item',
				formatter: "{a} <br/>{b} : {c} ({d}%)"
			},
			color: [
				"#6E8CD7",
				"#1C4194",
				"#4697CE",
				"#BAC3D2",
				"#1781A4",
				"#60B1CC",
				"#12AF9F",
			],
			legend: {
				orient : 'vertical',
				x : 'left',
				data:nameData,
				itemWidth:fontChart(0.18),
				itemHeight:fontChart(0.15),
				itemGap :fontChart(0.09),
				textStyle:{
					color:'#8db6d8',
					fontSize:fontChart(0.16)
				}
			},
			calculable : true,
			series : [
				{
					name:'电子台账异常机构',
					type:'pie',
					center: ["70%", "45%"],
					radius : ['50%', '80%'],
					itemStyle : {
						normal : {
							label : {
								show : false
							},
							labelLine : {
								show : false
							}
						},
						emphasis : {
							label : {
								show : false,
								position : 'center',
								textStyle : {
									fontSize : fontChart(12)
								}
							}
						}
					},
					data:valueData
				}
			]
		};
		// 3. 配置项和数据给我们的实例化对象
		myChart.setOption(option);
		// 4. 当我们浏览器缩放的时候，图表也等比例缩放
		window.addEventListener("resize", function() {
			// 让我们的图表调用 resize这个方法
			myChart.resize();
		});
	};
	//绘制处方异常医疗机构分布饼图
	function drawpresDailyPie(data) {
		if (data.length == 0) {
			return;
		} else {
			var nameData = [];
			var valueData = [];
			for(i=0;i<data.length;i++){
				nameData.push(data[i].name);
				valueData.push(data[i]);
			}
		}
		// 1. 实例化对象
		var myChart = echarts.init(document.querySelector("#presDailyPie"));
		// 2. 指定配置项和数据
		option = {
			tooltip : {
				trigger: 'item',
				formatter: "{a} <br/>{b} : {c} ({d}%)"
			},
			color: [
				"#6E8CD7",
				"#1C4194",
				"#4697CE",
				"#BAC3D2",
				"#1781A4",
				"#60B1CC",
				"#12AF9F",
			],
			legend: {
				orient : 'vertical',
				x : 'left',
				data:nameData,
				itemWidth:fontChart(0.18),
				itemHeight:fontChart(0.15),
				itemGap :fontChart(0.09),
				textStyle:{
					color:'#8db6d8',
					fontSize:fontChart(0.16)
				}
			},
			series : [
				{
					name:'处方异常机构',
					type:'pie',
					center: ["70%", "45%"],
					radius : ['50%', '80%'],
					itemStyle : {
						normal : {
							label : {
								show : false
							},
							labelLine : {
								show : false
							}
						},
						emphasis : {
							label : {
								show : false,
								position : 'center',
								textStyle : {
									fontSize : fontChart(12)
								}
							}
						}
					},
					data:valueData
				}
			]
		};
		// 3. 配置项和数据给我们的实例化对象
		myChart.setOption(option);
		// 4. 当我们浏览器缩放的时候，图表也等比例缩放
		window.addEventListener("resize", function() {
			// 让我们的图表调用 resize这个方法
			myChart.resize();
		});
	};
	//处方违规数趋势（折线图）
	function drawPreTimeLine(data) {
		if (data.length == 0) {
			return;
		} else {
			var nameData = [];
			var valueData = [];
			for(i=0;i<data.length;i++){
				nameData.push(data[data.length-i-1].name);
				valueData.push(data[data.length-i-1].value);
			}
		}
		// 基于准备好的dom，初始化echarts实例
		var myChart = echarts.init(document.querySelector("#prescriptionTrend"));
		// 2. 指定配置和数据
		option = {
			tooltip: {
				trigger: "axis",
				axisPointer: {
					lineStyle: {
						color: "#dddc6b"
					}
				}
			},
			legend: {
				top: "0%",
				textStyle: {
					color: "rgba(255,255,255,.5)",
					fontSize: "12"
				}
			},
			grid: {
				left: "30",
				top: "10",
				right: "5",
				bottom: "20",
				containLabel: true
			},

			xAxis: [
				{
					type: "category",
					boundaryGap: false,
					axisLabel: {
						textStyle: {
							color: "rgba(255,255,255,.6)",
						},
					},
					axisLine: {
						lineStyle: {
							color: "#8db6d8"
						},
					},

					data: nameData,

					axisLabel: {
						interval:0, //坐标刻度之间的显示间隔，默认就可以了（默认是不重叠）
						rotate:40   //调整数值改变倾斜的幅度（范围-90到90）
					},
					grid: {
						left: '0%',
						bottom:'90%'
					},
				},
				{
					axisPointer: { show: false },
					axisLine: { show: false },
					position: "bottom",
					offset: 20
				}
			],

			yAxis: [
				{
					type: "value",
					axisTick: { show: false },
					axisLine: {
						lineStyle: {
							color: "rgba(255,255,255,.1)"
						}
					},
					axisLabel: {
						textStyle: {
							color: "rgba(255,255,255,.6)",
							fontSize: 12
						}
					},

					splitLine: {
						lineStyle: {
							color: "rgba(255,255,255,.1)"
						}
					}
				}
			],
			series: [
				{
					name: "处方违规数",
					type: "line",
					smooth: true,
					symbol: "circle",
					symbolSize: 5,
					showSymbol: false,
					lineStyle: {
						normal: {
							color: "#0184d5",
							width: 2
						}
					},
					areaStyle: {
						normal: {
							color: new echarts.graphic.LinearGradient(
								0,
								0,
								0,
								1,
								[
									{
										offset: 0,
										color: "rgba(1, 132, 213, 0.4)"
									},
									{
										offset: 0.8,
										color: "rgba(1, 132, 213, 0.1)"
									}
								],
								false
							),
							shadowColor: "rgba(0, 0, 0, 0.1)"
						}
					},
					itemStyle: {
						normal: {
							color: "#0184d5",
							borderColor: "rgba(221, 220, 107, .1)",
							borderWidth: 12
						}
					},
					data: valueData
				}
			]
		};
		// 3. 把配置和数据给实例对象
		myChart.setOption(option);

		// 重新把配置好的新数据给实例对象
		myChart.setOption(option);
		window.addEventListener("resize", function() {
			myChart.resize();
		});
	};
	//绘制台账异常数趋势图
	function drawWarningTimeLine(data) {
		if (data.length == 0) {
			return;
		} else {
			var nameData = [];
			var valueData = [];
			for(i=0;i<data.length;i++){
				nameData.push(data[data.length-i-1].name);
				valueData.push(data[data.length-i-1].value);
			}
		}
		// 基于准备好的dom，初始化echarts实例
		var myChart = echarts.init(document.querySelector("#warningTimeLine"));

		// (1)准备数据
		var data = {
			year: [
				[24, 40, 101, 134, 90, 230, 210, 230, 120, 230, 210, 120]
			]
		};

		// 2. 指定配置和数据
		option = {
			tooltip: {
				trigger: "axis",
				axisPointer: {
					lineStyle: {
						color: "#dddc6b"
					}
				}
			},
			legend: {
				top: "0%",
				textStyle: {
					color: "rgba(255,255,255,.5)",
					fontSize: "12"
				}
			},
			grid: {
				left: "30",
				top: "10",
				right: "5",
				bottom: "20",
				containLabel: true
			},

			xAxis: [
				{
					type: "category",
					boundaryGap: false,
					axisLabel: {
						textStyle: {
							color: "rgba(255,255,255,.6)",
						},
					},
					axisLine: {
						lineStyle: {
							color: "#8db6d8"
						},
					},

					data: nameData,

					axisLabel: {
						interval:0, //坐标刻度之间的显示间隔，默认就可以了（默认是不重叠）
						rotate:40   //调整数值改变倾斜的幅度（范围-90到90）
					},
					grid: {
						left: '0%',
						bottom:'90%'
					},
				},
				{
					axisPointer: { show: false },
					axisLine: { show: false },
					position: "bottom",
					offset: 20
				}
			],

			yAxis: [
				{
					type: "value",
					axisTick: { show: false },
					axisLine: {
						lineStyle: {
							color: "rgba(255,255,255,.1)"
						}
					},
					axisLabel: {
						textStyle: {
							color: "rgba(255,255,255,.6)",
							fontSize: 12
						}
					},

					splitLine: {
						lineStyle: {
							color: "rgba(255,255,255,.1)"
						}
					}
				}
			],
			series: [
				{
					name: "台账异常数",
					type: "line",
					smooth: true,
					symbol: "circle",
					symbolSize: 5,
					showSymbol: false,
					lineStyle: {
						normal: {
							color: "#0184d5",
							width: 2
						}
					},
					areaStyle: {
						normal: {
							color: new echarts.graphic.LinearGradient(
								0,
								0,
								0,
								1,
								[
									{
										offset: 0,
										color: "rgba(1, 132, 213, 0.4)"
									},
									{
										offset: 0.8,
										color: "rgba(1, 132, 213, 0.1)"
									}
								],
								false
							),
							shadowColor: "rgba(0, 0, 0, 0.1)"
						}
					},
					itemStyle: {
						normal: {
							color: "#0184d5",
							borderColor: "rgba(221, 220, 107, .1)",
							borderWidth: 12
						}
					},
					data: valueData
				}
			]
		};
		// 3. 把配置和数据给实例对象
		myChart.setOption(option);

		// 重新把配置好的新数据给实例对象
		myChart.setOption(option);
		window.addEventListener("resize", function() {
			myChart.resize();
		});
	};

	// 实时监控记录区域
	function showRealTimeMonitor2(realTimeMonitorList){

		// 监视tbl
		var $realTimeMonitorList = $('#realTimeMonitorList');
		var oldId = [];
		$realTimeMonitorList.find('li').each(function (idx,a) {
			oldId.push( $(a).data('id'));
		});
		// 列表刷新用数组
		var msgList = [];
		$(realTimeMonitorList).each(function(idx,a){
			if (a.title!=null && a.title.length>0) {
				// 数据是否在显示列中？不在的话，添加到队列
				if (!oldId.includes(a.id) ){
					msgList.push(a);
				}
			}
		});
		var e ='';

		if ( msgList.length == 0 && $realTimeMonitorList.children().length == 0) {
			e+='<li data-id=""><span style="text-align: center;">暂无数据</span></li>';
			$realTimeMonitorList.append(e);
			return;
		}
		/* else if (msgList.length > 0 && $realTimeMonitorListBody.find('td')[0].innerHTML == '暂无数据') {
			$realTimeMonitorListBody.empty();
		}*/

		for (msgIndex in msgList) {
			var a = msgList[msgIndex];
			e+='<li data-id="'+ a.id +'"><span style="text-align: left;width: 14%;float:left;font-size: '+fontChart(0.15)+';overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">'+ (new Date(a.violateTm).format('yyyy-MM-dd')) +'</span><span style="text-align: left;width:60%;float:left;font-size: '+fontChart(0.15)+';overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">'+ a.institutionName+'</span><span style="text-align: left;width: 26%;float:right;font-size: '+fontChart(0.15)+';overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">'+a.title+'</span></li>'
		}

		var $ele = $(e);
		$realTimeMonitorList.prepend($ele.hide());
		$ele.fadeIn(800);
		if ( msgList.length > 0 && $realTimeMonitorList.children().length > 6) {
			var trs = [];
			for (i=6;i<$realTimeMonitorList.children().length;i++) {
				trs.push(i);
			}
			$realTimeMonitorList.children('tr').filter(':eq(' + trs.join('), :eq(') + ')').remove();
		}
		return;
	}

	// 绘制近八周趋势
	function drawHalfYeadTrend( data ){
		// 基于准备好的dom，初始化echarts实例
		var divChart = document.getElementById('halfYeadTrend');
		var halfYeadTrend = echarts.init(divChart);

		window.addEventListener('resize', function () {
			halfYeadTrend.resize();
		});

		var timeLine = [];
		var badPracticing = [];
		var badBehavior= [];

		var violateTimeLine = data.violateTimeLine;
		var warningTimeLine = data.warningTimeLine;

		for (var i=0;i<violateTimeLine.length;i++){

			var sumYm = violateTimeLine[i].name;
			timeLine.push(Number(sumYm.substring(4))+'月');//月份
			badPracticing.push(violateTimeLine[i].value);//处方违规值[按月]
			badBehavior.push(warningTimeLine[i].value);//异常警告值[按月]
		}

		// 指定图表的配置项和数据
		option = {
			title : {
				text: '监控趋势',
				textStyle:{
					color:'#A5CCED',
					fontSize:12
				}
			},
			tooltip : {
				trigger: 'axis'
			},
			color:['#F1F005','#38DDCC'],
			legend: {
				textStyle:{
					color:'#A5CCED'
				},
				data:['处方违规数','卫生警告数']
			},
			toolbox: {
				show : false,
				feature : {
					mark : {show: true},
					dataView : {show: true, readOnly: false},
					magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
					restore : {show: true},
					saveAsImage : {show: true}
				}
			},
			calculable : true,
			xAxis : [
				{
					type : 'category',
					boundaryGap : false,
					axisLabel: {
						textStyle: {
							color: '#A5CCED',//坐标值得具体的颜色
						}
					},
					data : timeLine
				}
			],
			yAxis : [
				{
					type : 'value',
					axisLabel: {
						textStyle: {
							color: '#A5CCED',//坐标值得具体的颜色
						}
					}
				}
			],
			grid: {
				left: '3%',
				right: '3%',
				bottom: '2%',
				containLabel: true
			},
			series : [
				{
					name:'处方违规数',
					type:'line',
					stack: '总量',
					lineStyle: {
						normal:{
							color: '#F1F005',
							width: 2,
							type: 'solid'
						}

					},
					data:badPracticing
				},
				{
					name:'卫生警告数',
					type:'line',
					stack: '总量',
					lineStyle: {
						normal:{
							color: '#38DDCC',
							width: 2,
							type: 'solid'
						}
					},
					data:badBehavior
				}
			]
		};

		// 使用刚指定的配置项和数据显示图表。
		halfYeadTrend.setOption(option);
	}

	//全屏
	function fullScreen(){
		var el = document.documentElement;
		var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullscreen;
		if(typeof rfs != "undefined" && rfs) {
			rfs.call(el);
		};
		return;
	}
	//退出全屏
	function exitScreen(){
		if (document.exitFullscreen) {
			document.exitFullscreen();
		}
		else if (document.mozCancelFullScreen) {
			document.mozCancelFullScreen();
		}
		else if (document.webkitCancelFullScreen) {
			document.webkitCancelFullScreen();
		}
		else if (document.msExitFullscreen) {
			document.msExitFullscreen();
		}
		if(typeof cfs != "undefined" && cfs) {
			cfs.call(el);
		}
	}

	/**
	 * 退出登录
	 */
	function logout() {
		WeKnow.submit('logout');
	}

	// 首页刷新
	function refreshWindow(){
		// 时间刷新
		MY_HOME_PAGE.setDateTime();
		//页面初始化查询地图数据
		MY_HOME_PAGE.loadMap();
		// 页面初期数据
		//MY_HOME_PAGE.loadItem();

	}

	function loadWeather(){

		$.ajax({
			type: "POST",
			url: "invs_home_page.do/load_weather",
			data: {},
			async: true,//异步调用
			success: function(data) {
				WeKnow.closeLoading();
				if (!WeKnow.filterAjaxResult(data)) return false; // session过期check

				if (data.errcode == 0) {

					var weather = data.weather;

					$('#weather-image').prop('src',weather.weatherIconUrl);
					$('#weather').text(weather.cond_txt_d+ ' ' + weather.tmp_min+'℃-' + weather.tmp_max+ '℃');
				}
			}
		});

	}

	return {
		loadItem:loadItem,
		loadMap:loadMap,
		setDateTime:setDateTime,
		fullScreen:fullScreen,
		exitScreen:exitScreen,
		refreshWindow:refreshWindow,
		loadWeather:loadWeather
	}
})();


var ua;
// 首页刷新定时钟
//window.setInterval("MY_HOME_PAGE.refreshWindow()", 5000);

$(document).ready(function() {
	$('.date_fillter').each(function(idx,a){
		$(a).val(1);//测试阶段，默认为一周数据
	});
	ua = getUID();
	// 大屏只在第一次出现load页
	WeKnow.loading();
	//MY_HOME_PAGE.refreshWindow();
	WeKnow.closeLoading();
	//实时监控记录无缝滚动
	//setInterval(function(){monitorRoll()}, 2000);
	var myar = setInterval(function(){monitorRoll()}, 2000);
	//当鼠标放上去的时候，滚动停止，鼠标离开的时候滚动开始
	$("#realTimeMonitorList").hover(function () {
		clearInterval(myar);
		}, function () {
		myar = setInterval('monitorRoll("#realTimeMonitorList")', 2000)
	});
/*	$('#realTimeMonitorList').on('mouseover',function () {
		$('#realTimeMonitorList').stop(true);
	});
	$('#realTimeMonitorList').on('mouseout',function () {
		$('#realTimeMonitorList').stop(false,true);
	});*/
	$('.fullScreen').on('change','select.date_fillter',function(){
		// 暂定所有选择框连动
		var $that = $(this);
		var selectVal = $that.val();

		$('select.date_fillter').each(function(idx,d){
			$(d).val(selectVal);
		});

		//MY_HOME_PAGE.refreshWindow();
	});

	//setInterval("MY_HOME_PAGE.refreshWindow();",60000);//每隔1分钟刷新主页数据

//	setInterval("MY_HOME_PAGE.loadWeather();",60*60*2000);//2个小时执行一次天气刷新

	// 全屏
	$('.fullScreen-toggle').on('click',function(){
		var $that = $(this);
		// 全屏化7
		var target =$that.prop('id');
		if ( target =='full_scr' ) {
			$('nav').hide();

			MY_HOME_PAGE.fullScreen();
			$('div.fullScreen').css('top',0);
			$('body').css('overflow-y',"hidden");
		} else {
			$('nav').show();
			MY_HOME_PAGE.exitScreen();
			//$('div.fullScreen').css('top','45px');
			$('body').css('overflow-y',"scroll");
		}
		//全屏、退出全屏 图标切换
		$('.fullScreen-toggle').toggle();

	});

	// 首页 → 工作台 切换
	var ACTIVIE_CLASS = 'active_tab';
	$('.my_tab').on('click',function(){
		var $that = $(this);
		// 切换tab选中状态
		$('.active_tab').removeClass(ACTIVIE_CLASS);
		// 选中tab高亮显示
		$that.addClass( ACTIVIE_CLASS );
		// 是否显示菜单
		var activeTabId = $that.prop('id');
		if ( activeTabId == 'workbench' ){
			// 跳转至业务页
			WeKnow.submit("main.do");
		}
	});

	// 退出并返回登录页面
	$("li#logout").on("click", function() {
		WeKnow.submit($(this).data("url"));
	});

	// 获得天气
	//MY_HOME_PAGE.loadWeather();
});

// 获取唯一值
function getUID() {
	return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
		var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
		return v.toString(16);
	});
}

//跳转工作台
function toWorkbench(title,status,date,otherData) {
	var today = $('.date_fillter').eq(0).val();// 0：今日  1：本周 10：全部
	if(date == "all"){
		today = "10";
	}
	WeKnow.submit("main.do?initPageTitle="+ title +"&today=" + today + "&status=" + status + "&otherData=" + otherData);
}
//自适应字体大小
function fontChart(res) {
	//获取到屏幕的宽度
	var clientWidth =
		window.innerWidth ||
		document.documentElement.clientWidth ||
		document.body.clientWidth;
	if (!clientWidth) return; //报错拦截：
	var fontSize = 80 * (clientWidth / screen.width);
	return res * fontSize;
}
//实时监控列表滚动
function  monitorRoll() {
	var $parent = $('#realTimeMonitorList');
	var $first = $parent.find('li:first');
	var height = $first.height();
	/*$first.animate({
		height: 0   //或者改成： marginTop: -height + 'px'
	}, 500, function() {// 动画结束后，把它插到最后，形成无缝
		$first.css('height', height).appendTo($parent);
	});*/
	$first.animate({
		height: 0
	}, 500, function () {
		$first.css('height', height).appendTo($parent);
	});
};